package com.one.rope.mvp.web.controller.user;

import com.one.rope.mvp.basecore.annotation.LogMethod;
import com.one.rope.mvp.basecore.bean.ResponseObject;
import com.one.rope.mvp.web.common.dto.user.person.AddIntentionDTO;
import com.one.rope.mvp.web.common.dto.user.person.PersonIndexVO;
import com.one.rope.mvp.web.common.dto.user.person.RecommendListVO;
import com.one.rope.mvp.web.common.util.ObjectUtils;
import com.one.rope.mvp.web.controller.BaseController;
import com.one.rope.mvp.web.service.user.PersonDataService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 小程序人才端数据控制器
 * <p>
 *
 * @author ： Weijian.Liu
 * @date ： 2020/3/15 19:28
 */
@Api(tags = "B2小程序端-人才端数据模块")
@RequestMapping("/user")
@RestController
@Slf4j
public class PersonDataController extends BaseController {

  @Autowired
  PersonDataService personService;

  @LogMethod
  @ApiOperation(value = "001人才端首页", notes = "人才端首页接口", response = PersonIndexVO.class)
  @GetMapping("/api/person/index")
  public ResponseObject<PersonIndexVO> personIndex(){
    try {
      return personService.personIndex();
    } catch (Exception e) {
      log.error("/user/api/person/index接口异常", e);
      return ResponseObject.systemError(e);
    }
  }

  @LogMethod
  @ApiOperation(value = "002我的推荐列表", notes = "我的推荐列表接口", response = RecommendListVO.class)
  @GetMapping("/api/person/recommendList")
  public ResponseObject<List<RecommendListVO>> recommendList(){
    try {
      return personService.recommendList();
    } catch (Exception e) {
      log.error("/user/api/person/recommendList接口异常", e);
      return ResponseObject.systemError(e);
    }
  }

  @LogMethod
  @ApiOperation(value = "003添加意向", notes = "添加意向接口")
  @PostMapping("/api/person/addIntention")
  public ResponseObject addIntention(@RequestBody AddIntentionDTO requestDTO){
    ObjectUtils.requestNonNull(requestDTO.getTargetId(), "目标用户id不能为空");
    try {
      return personService.addIntention(requestDTO);
    } catch (Exception e) {
      log.error("/user/api/person/addIntention接口异常", e);
      return ResponseObject.systemError(e);
    }
  }
}
